using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Storage;
using Microsoft.Xna.Framework.Content;

namespace BriansClimb.GameObjects
{
    /// <summary>
    /// This is a game component that handles moving stats and file names from the PlayerCustomize scene 
    /// to the player climb scene.
    /// </summary>
    public class FileStatManager : Microsoft.Xna.Framework.GameComponent
    {

        protected string height=null;
        protected int weight=0;
        protected int strength = 0;
        protected int flexibility=0;
        protected float stamina=0;
        protected float friction=0;
        //Name of the file to load
        protected string fileName;
        protected float staminaIn;
        protected float staminaBarValue = 0;
        protected float climberFlexibility;
        
        /// <summary>
        /// The Property representing the height of the climber.  Depricated.
        /// </summary>
        public string heightStat
        {
            get { return height; }
            set { height = value; }
        }        

        /// <summary>
        /// The Property representing the weight of the climber.
        /// </summary>
        public int weightStat
        {
            get { return weight; }
            set { weight = value; }
        }

        /// <summary>
        /// The Property representing the strength of the climber.
        /// </summary>
        public int strengthStat
        {
            get { return strength; }
            set { strength = value; }           
        }

        /// <summary>
        /// The Property representing the flexibility of the climber.
        /// </summary>
        public int flexibilityStat
        {
            get { return flexibility; }
            set { flexibility = value; }
        }        

        /// <summary>
        /// The Property that represents the file to load for the player climb scene.
        /// </summary>
        public string fileToLoad
        {
            get { return fileName; }
            set { fileName = value; }
        }

        /// <summary>
        /// The Property that represents the StaminaBar(now TimerBar) for the player climb scene.
        /// </summary>
        public float StaminaBarValue
        {
            get { return staminaBarValue; }
        }

        /// <summary>
        /// The Property that represents the flexibility of the climber.
        /// </summary>
        public float ClimberFlexibility
        {
            get { return climberFlexibility; }
            set { climberFlexibility = value; }
        }

        /// <summary>
        /// The Property that represents the stamina of the climber.
        /// </summary>
        public float climberStamina
        {            
            set { staminaIn = value; }
        }

        /// <summary>
        /// The Property that represents the climber's friction.
        /// </summary>
        public float climberFriction
        {
            get { return friction; }
            set { friction = value; }
        }      

        /// <summary>
        /// The default constructor.
        /// </summary>
        /// <param name="game">Master game object.</param>
        public FileStatManager(Game game)
            : base(game)
        {
            strength = 0;
            flexibility = 0;
            weight = 0;
            fileName = null;
        }

        /// <summary>
        /// Normalizes the stats of the stamina bar and the climber's flexibility
        /// so they can be easilly utilized in the player climb scene.
        /// </summary>
        private void normalizeStats()
        {
            /* Checks the weight of the climber given by player customize scene and
             * gives the stamina bar a value based on it.  The value is used by the
             * stamina bar to determine the rate at which it drops.
             */            
            
            switch (weight)
            {
                case 140:
                    staminaBarValue = .02f;
                    break;
                case 145:
                    staminaBarValue = .02f;
                    break;
                case 150:
                    staminaBarValue = .0175f;
                    break;
                case 155:
                    staminaBarValue = .0175f;
                    break;
                case 160: 
                    staminaBarValue = .0150f;
                    break;
                case 165: 
                    staminaBarValue = .0150f;
                    break;
                case 170: 
                    staminaBarValue = .0125f;
                    break;
                case 175: 
                    staminaBarValue = .0125f;
                    break; 
                case 180: 
                    staminaBarValue = .0100f;
                    break;
                case 185: 
                    staminaBarValue = .0100f;
                    break;
            }
            /* Checks the flexibility of the climber given by player customize scene and
             * gives the climberflexibility a value based on it.  The value is used by the
             * climber to determine how flexible it is.
             */
            switch (flexibility)
            {
                case 1:
                    climberFlexibility = 1.57f;
                    break;
                case 2:
                    climberFlexibility = 1.77f;
                    break;
                case 3:
                    climberFlexibility = 2f;
                    break;
                case 4:
                    climberFlexibility = 2.25f;
                    break;
                case 5:
                    climberFlexibility = 2.5f;
                    break;
            }


            //Calculating the normalized friction value
            float w = 25000f / (float)weightStat;
            float s = 50f * (float)strengthStat;
            float friction = w + s;
            friction = friction * 15f;
            friction = friction / 408f;
            this.climberFriction = friction;
            this.climberFlexibility = climberFlexibility;
        }

        /// <summary>
        /// Allows the game component to perform any initialization it needs to before starting
        /// to run.  This is where it can query for any required services and load content.
        /// </summary>
        public override void Initialize()
        {
            // TODO: Add your initialization code here

            base.Initialize();
        }

        /// <summary>
        /// Allows the game component to update itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public override void Update(GameTime gameTime)
        {
            normalizeStats();
            base.Update(gameTime);
        }
    }
}